import { BaseWindow } from "../../../../component/window/BaseWindow";
import { SMoney } from "../../../../../Message/Game/SMoney";
import { Cache } from "../../../cache/Cache";
import { ShopItemInfo } from "../../../resource/info/ShopItemInfo";
import { ShopConfig } from "../../../resource/ShopConfig";
import { Language } from "../../../../../extend/language/Language";
import { WindowEvent } from "../../../../component/window/WindowEvent";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { PopupManager } from "../../../manager/PopupManager";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { ItemData } from "../../../resource/info/ItemData";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { EProp } from "../../../../../Message/Public/EProp";
import { EBind } from "../../../../../Message/Public/EBind";
import { ObjCreate } from "../../common/ObjCreate";
import { GameConst } from "../../../../component/gconst/GameConst";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { NumInput } from "../../common/NumInput";
import { _materials } from "../../../../../this/_materials";
import { _autoBuy } from "../../../../../this/_autoBuy";
type int = number;
//class MountMutiWashPannel
    
    export  class MountMutiWashPannel extends BaseWindow
    {
        constructor()
        {
            super();
            this._materials = new Array<any>();
            this.init();
            return;
        }

        /* internal  */get sMoney(): SMoney
        {
            return Cache.instance.login.loginGame.money;
        }

        /* internal  */get needCostCoin(): int
        {
            var loc1=this._cost * this._washNumInput.currentNum;
            return loc1;
        }

        /* internal  */get ownCoin(): int
        {
            return this.sMoney.coin + this.sMoney.coinBind;
        }

        /* internal  */get shopItemInfo(): ShopItemInfo
        {
            var loc1=ShopConfig.instance.getShopItemInfoByCode(14108300, 1702);
            return loc1;
        }

        /* internal  */init(): void
        {
            this.setSize(320, 205);
            this.title = Language.getString(54049);
            this.titleHeight = 26;
            this.addEventListener(WindowEvent.CLOSE, this.onWindowClose);
            return;
        }

        /* internal  */onInputChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._washNumInput.currentNum;
            this.updateNumText();
            return;
        }

        protected /* override */ closeBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.dispose();
            return;
        }

        /* internal  */onClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (this.ownCoin < this.needCostCoin) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin, this.needCostCoin - this.ownCoin));
            }
            else 
            {
                loc1 = {"posType": this._mountIData.posType, "mountUid": this._mountIData.uid, "count": this._washNumInput.currentNum, "materials": _materials, "autoBuy": _autoBuy};
                Dispatcher.dispatchEvent(new DataEvent(EventName.MountGoWash, loc1));
                PopupManager.removePopup(this);
            }
            return;
        }

        /* internal  */onWindowClose(arg1: WindowEvent): void
        {
            PopupManager.removePopup(this);
            return;
        }

        /* internal  */onWindowShowHandler(arg1: WindowEvent): void
        {
            return;
        }

        /* internal  */updateNumText(): void
        {
            var loc1="#00ff00";
            if (this.ownCoin < this.needCostCoin) 
            {
                loc1 = "#ff0000";
            }
            this._costCoinTextField.htmlText = HTMLUtil.addColor(Language.getString(11125) + this.needCostCoin.toString(), loc1);
            this._costItemTextField.htmlText = HTMLUtil.addColor(this.shopItemInfo.itemInfo.item.name + " *" + this._washNumInput.currentNum.toString(), "#00ff00");
            return;
        }

        /* internal  */getItemIco(arg1: number=103, arg2: number=103): Object /* flash.display.Sprite */
        {
            var loc2=null;
            var loc1=new Object /* flash.display.Sprite */();
            (loc2 = GlobalClass.getBitmap(ImagesConst.PackItemBg)).x = 0;
            loc2.y = 0;
            loc1.addChild(loc2);
            var loc3;
            (loc3 = new BaseItem()).itemData = new ItemData(14108300);
            loc3.width = 32;
            loc3.height = 32;
            loc3.isDragAble = false;
            loc3.isDropAble = false;
            loc3.x = loc2.x + 3;
            loc3.y = loc2.y + 3;
            loc1.addChild(loc3);
            loc1.width = arg1;
            loc1.height = arg2;
            return loc1;
        }

        public updateMoney(): void
        {
            this.updateNumText();
            return;
        }

        public mutiWash(arg1: Object): void
        {
            var loc3=0;
            var loc9=0;
            this._autoBuy = arg1.autoBuy;
            this._mountIData = arg1.mountIData;
            this._materials = arg1.materials;
            this.useBindMaterial = arg1.useBindMaterial;
            var loc1=this.sMoney.coin + this.sMoney.coinBind;
            var loc2=loc1 / this._cost;
            var loc4=this.shopItemInfo.tshopSell.offer > 0 ? this.shopItemInfo.tshopSell.offer : this.shopItemInfo.tshopSell.price;
            var loc5=Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(ECategory._ECategoryProp, EProp._EPropMountRefreshGrow, -1, -1);
            var loc6=Cache.instance.pack.backPackCache.getItemByCode(14108300);
            if (this.useBindMaterial && this._autoBuy) 
            {
                loc3 = (loc9 = Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(ECategory._ECategoryProp, EProp._EPropMountRefreshGrow, -1, -1, EBind._EBindYes)) + this.sMoney.gold / loc4;
            }
            else if (this._autoBuy) 
            {
                loc3 = this.sMoney.gold / loc4;
                this._sumItemTextField.htmlText = HTMLUtil.addColor("0", "#ffff00");
            }
            else 
            {
                loc3 = loc5;
            }
            var loc7=Math.min(loc2, loc3);
            if (loc2 < 1) 
            {
                loc7 = loc3;
            }
            if (loc7 > this.MAX_NUM) 
            {
                loc7 = this.MAX_NUM;
            }
            this._washNumInput.maxNum = loc7;
            this._washNumInput.currentNum = loc7;
            var loc8=this.sMoney.coin + this.sMoney.coinBind;
            this._sumCoinTextField.htmlText = HTMLUtil.addColor(Language.getString(11125) + loc8.toString(), "#00ff00");
            this._sumItemTextField.htmlText = HTMLUtil.addColor(this.shopItemInfo.itemInfo.item.name + " *" + loc5.toString(), "#00ff00");
            this.updateNumText();
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            super.dispose(arg1);
            PopupManager.removePopup(this);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(19, 40, 281, 152, this);
            var loc1=ObjCreate.createGTextField(Language.getString(71554), 55, 45, 200, 25, this);
            loc1.htmlText = HTMLUtil.addColor(Language.getString(71554), "#ffffff");
            this._item = this.getItemIco();
            this._item.x = 40;
            this._item.y = loc1.y + loc1.textHeight + 18;
            addChild(this._item);
            var loc2=ObjCreate.createGTextField("", this._item.x + 60, this._item.y - 5, 100, 25, this);
            loc2.htmlText = "<font color=\'#ffff00\'>" + Language.getString(71556) + ":</font>";
            this._washNumInput = ObjCreate.createNumInput(loc2.x, loc2.y + loc2.textHeight + 10, this);
            this._washNumInput.addEventListener(flash.events.Event.CHANGE, this.onInputChangeHandler);
            this._useBtn = ObjCreate.createGButton(Language.getString(71509), this._washNumInput.x + this._washNumInput.width + 8, this._washNumInput.y - 5, 70, 28, this, "ButtonRedMini");
            this._useBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClickHandler);
            var loc3=ObjCreate.createGTextField("", this._item.x - 10, this._washNumInput.y + 37, 90, 25, this);
            loc3.htmlText = HTMLUtil.addColor(Language.getString(90270), "#00ff00");
            this._cost = GameConst.MountWashCostCoin;
            this._costCoinTextField = ObjCreate.createGTextField("", loc3.x + loc3.textWidth - 2, loc3.y, 120, 25, this);
            var loc4=this._costCoinTextField.x + 95;
            var loc5;
            (loc5 = ObjCreate.createGTextField("", this._item.x - 10, 155, 100, 25, this)).htmlText = HTMLUtil.addColor(Language.getString(90271), "#00ff00");
            this._sumCoinTextField = ObjCreate.createGTextField("", loc5.x + loc5.textWidth - 2, loc5.y, 120, 25, this);
            this._costItemTextField = ObjCreate.createGTextField("", loc4, this._costCoinTextField.y, 120, 25, this);
            this._sumItemTextField = ObjCreate.createGTextField("", loc4, this._sumCoinTextField.y, 120, 25, this);
            return;
        }

        /* internal */ /* const */MAX_NUM: int=999;

        /* internal */ /* var */_sumCoinTextField: GTextFiled;

        /* internal */ /* var */_costCoinTextField: GTextFiled;

        /* internal */ /* var */_sumItemTextField: GTextFiled;

        /* internal */ /* var */_costItemTextField: GTextFiled;

        /* internal */ /* var */_useBtn: GButton;

        /* internal */ /* var */_cost: number;

        /* internal */ /* var */_washNumInput: NumInput;

        /* internal */ /* var */_autoBuy: Boolean;

        /* internal */ /* var */_item: Object /* flash.display.Sprite */;

        /* internal */ /* var */_mountIData: ItemData;

        /* internal */ /* var */_materials: Array<any>;

        /* internal */ /* var */useBindMaterial: Boolean;
    }
